package com.vijay.extension.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;

public class SpringExtensionFactoryBean<T> implements FactoryBean<T>, BeanFactoryAware {


    private BeanFactory factory;

    private Class<T> extensionInterface;


    @Override
    public T getObject()  {
        return new SpringExtensionProxyFactory<>(extensionInterface).newInstance(factory);
    }

    @Override
    public Class<T> getObjectType() {
        return extensionInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    @Override
    public void setBeanFactory(BeanFactory factory) throws BeansException {

        this.factory = factory;

    }

    public void setExtensionInterface(Class<T> extensionInterface) {
        this.extensionInterface = extensionInterface;
    }
}
